<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=s, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue_2.5.22.js"></script>
  <script src="../vue-router_3.0.2.js"></script>
</head>

<body>
  <div id="app">
    <router-link to='/shop/1'>商品列表</router-link>
    <router-link to='/shop/2'>商品列表</router-link>
    <router-link to='/shop/3'>商品列表</router-link>
    <router-link to='/shop/4'>商品列表</router-link>
    <router-link to='/shop/5'>商品列表</router-link>
    <router-link :to="{ name: 'shop', params: {id: 6} }">商品列表</router-link>
    <router-link to='/register'>注册</router-link>
    <router-view></router-view>
  </div>
  <script>
    var shop = {
      template: `<h4>商品详情 -- {{$route.params.id}}</h4>`
      // 使用$route.params.id 方法访问到动态路由的实际值
    }

    var Register = {
      template: `<h4>注册:</h4>`
    }

    const router = new VueRouter({
      routes: [
        { path: '/', redirect: '/login' },
        // ：id 一个参数 将动态的，会改变的位置，提取成一个参数，这个参数前面需要加 :
        // 建议name 名称与path 或component 一样，方便后期维护
        { path: '/shop/:id', component: shop, name: 'shop' },
        { path: '/register', component: Register }
      ]
    })

    var vm = new Vue({
      el: '#app',
      data: {},
      router
    })
  </script>
</body>

</html>